package com.shinemo.mpush.alloc.handler;

import com.shinemo.mpush.alloc.domain.OfflineMsgVo;
import com.shinemo.mpush.alloc.service.IOfflineMsgService;
import com.shinemo.mpush.alloc.service.OfflineMsgServiceImp;

import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by ThinkPad on 2017/9/23.
 */
public class OfflineMsgHandler {

    private IOfflineMsgService msgService = new OfflineMsgServiceImp();

    public void saveOfflineMsg(List<String> userIds, OfflineMsgVo offlineMsg){
        msgService.saveOfflineMsg(userIds,offlineMsg);
    }

    public void saveOfflineMsg(String userId, OfflineMsgVo offlineMsg){
        msgService.saveOfflineMsg(userId,offlineMsg);
    }
    public void delOfflineMsg(String userId,String msgId){
        msgService.delOfflineMsg(userId,msgId);
    }
    /**
     * 处理离线消息：将传入的参数设置到对于的属性上
     * @return
     */
    private final AtomicInteger idSeq = new AtomicInteger();
    public OfflineMsgVo setOfflineMsgVo(Map<String, Object> params){
        String docUid = (String) params.get("docUid");
        String dochandleUid = (String) params.get("dochandleUid");
        String actorType = (String) params.get("actorType");
        String actorsUid = (String) params.get("actorsUid");
        String readStatus = (String) params.get("readStatus");
        String listType = (String) params.get("listType");
        String title = (String) params.get("title");
        OfflineMsgVo msgVo = new OfflineMsgVo();
        msgVo.setDocUid(docUid);
        msgVo.setDochandleUid(dochandleUid);
        msgVo.setActorType(actorType);
        msgVo.setActorsUid(actorsUid);
        msgVo.setReadStatus(readStatus);
        msgVo.setListType(listType);
        msgVo.setTitle("公文信息");
        msgVo.setContent(title);
        //TODO 这里需要利用自增id的方式处理，才能添加多条消息
        msgVo.setMsgId((idSeq.get() % 2 + 1)+"");
        msgVo.setNid(idSeq.get() % 2 + 1);
        msgVo.setTicker("您有新的通知");
        return msgVo;
    }
}
